<template>
	<div id="LOVManage" class="LOVManage">
		<div class="newLOV">
			<span class="newLOVTitle">LOV管理</span><x-button mini @click.native="newLOV" type="primary" class="newLOVBtn">新建</x-button>
		</div>

		<swipeout class="vux-1px-tb">
			<swipeout-item transition-mode="follow" v-for="(item, index) in items" :key="index">
				<div slot="right-menu">
					<swipeout-button @click.native="deleteLOV(index, item)" type="primary">{{deleteText}}</swipeout-button>
				</div>
				<div slot="content">
					<cell :title="item.type">
						<div>
							<span>{{item.value}}</span>
						</div>
					</cell>
				</div>
			</swipeout-item>
		</swipeout>
	</div>
</template>

<script>
	import bus from '@/event/eventBus'
	import NetWorking from '../../../utils/networking'
	import {Swipeout, SwipeoutItem, SwipeoutButton, Cell, XButton} from 'vux'
	const URL = 'list_of_value'
	export default {
		name: "list-of-value-manage",
		components: {
			Swipeout,
			SwipeoutItem,
			SwipeoutButton,
			Cell,
			XButton
		},
		data() {
			return {
				items: [],
				deleteText: '删除'
			}
		},
		created: function () {
			bus.$emit("barController", 1)
			bus.$emit("setTopSimpleTitle", 'LOV管理')

			let _this = this
			NetWorking.doGet(
				URL,
				null,
				null
			).then(
				response => {
					let rs = response.data
					if(rs.error_code == 0){
						_this.items = rs.list_of_value
					}else{
						alert("rs.error_message")
					}
				}
			)
		},
		methods: {
			deleteLOV (index, lov) {
				let _this = this
				NetWorking.doDelete(
					URL,
					null,
					{
						params: {
							id: lov.id
						}
					}
				).then(
					response => {
						let rs = response.data
						if(rs.error_code == 0){
							_this.items.splice(index, 1)
						}else{
							alert(rs.error_message)
						}
					}
				)
			},
			newLOV() {
				this.$router.replace({ name: 'newListOfValue'})
			}
		}
	}
</script>

<style>
	.LOVManage {
		margin-top: 56px;
		margin-bottom: 100px;
	}

	.newLOV {
		margin-top: 0px !important;
		text-align: right;
		margin-right: 12px;
	}

	.newLOVTitle {
		font-size: 22px;
		font-weight: bold;
		float: left;
		margin-left: 12px;
	}

	.newLOVBtn {
		color: white !important;
		background-color: #efae1b !important;
		margin-bottom: 12px;
	}
</style>